import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;

/**
 * 客户端发送线程
 */

public class SeThread implements Runnable{

    private BufferedWriter bw;
    BufferedReader buf;
    public SeThread(BufferedWriter bw) {
        this.bw = bw;
    }


    @Override
    public void run() {
        try {
            buf = new BufferedReader(new InputStreamReader(System.in));

            //客户端发送消息
            System.out.println("请输入发送内容：");
            String line = null;
            while ((line = buf.readLine()) !=null){
                if("bye".equalsIgnoreCase(line)){
                    System.out.println("聊天结束！");
                    /*buf.close();
                    bw.close();*/
                    break;
                }
                bw.write(line);
                bw.newLine();
                bw.flush();
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (buf != null){
                try {
                    buf.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if(bw != null){
                try {
                    bw.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
